package com.wjm.demo.test1.net_test.http_url_test.ie_server;

import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

public class URLDemo {
    public static void main(String[] args) throws Exception {
        URL url = new URL("http://www.baidu.com");
        URLConnection urlConnection = url.openConnection();
        InputStream is = urlConnection.getInputStream();
        String headerField = urlConnection.getHeaderField("Content-Type");
        System.out.println(headerField);
        if("text/html".equals(headerField)){
            System.out.println("启动HTML解析器解析数据，并显示结果");
        }else{
            System.out.println("启动相应的解析器解析数据，并显示结果");
        }
        byte[] buf = new byte[1024];
        int len = is.read(buf);
        String text = new String(buf, 0, len);
        System.out.println(text);//结果是html数据
        is.close();
    }
}
